<?php

namespace app\controller\admin\sky;

use app\model\api\SkyConf;
use laytp\controller\Backend;
use laytp\library\CommonFun;
use think\facade\Db;
use think\response\Json;

/**
 * Class Team
 * @package app\controller\admin\sky
 */
class Conf extends Backend
{
    /**
     *
     * @var Activity
     */
    protected $model;
    protected $hasSoftDel=0;//是否拥有软删除功能

    protected $noNeedLogin = []; // 无需登录即可请求的方法
    protected $noNeedAuth = ['index', 'info']; // 无需鉴权即可请求的方法

    public $orderRule = ['sort' => 'desc', 'id' => 'asc'];

    public function _initialize()
    {
        $this->model = new SkyConf();
    }
    /**
     * @NodeAnotation(title="编辑")
     */
    public function edit()
    {
        try {
            $post = CommonFun::filterPostData($this->request->post());
            foreach ($post as $key=>$item){
                $this->model->where("key",$key)->update(['value'=>$item]);
            }
            $this->clearCache();
            return $this->success('保存成功');
        } catch (\Exception $e) {
            return $this->error($e->getMessage());
        }
    }

    public function info(){
        $confList = (new SkyConf())->select();
        $list = [];
        foreach ($confList as $item){
            $list[$item['key']] = $item['value'];
        }
        return $this->success('获取成功', $list);
    }
}